package com.yitiao.data_algorithms.leetcode.editor.cn;

import com.yitiao.data_algorithms.leetcode.editor.cn.base.ListNode;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;

class SubstringsOfSizeThreeWithDistinctCharacters {
    // 2022-08-24 13:03:17
    public static void main(String[] args) {
        Solution solution = new SubstringsOfSizeThreeWithDistinctCharacters().new Solution();
        solution.countGoodSubstrings("aababcabc");
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int countGoodSubstrings(String s) {
            // 窗口长度固定为三
            int ans = 0;
            Set<Character> set = new HashSet<Character>();
            int l = 0, r = 0;
            while (r < s.length()) {
                set.add(s.charAt(r));
                if (r - l + 1 > 3) {
                    set.clear();
                    l++;
                    set.add(s.charAt(l));
                    set.add(s.charAt(l+1));
                    set.add(s.charAt(l+2));
                }
                if (set.size() == 3) {
                    ans++;
                }
                r++;
            }
            return ans;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}